package utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


import base.BaseBean;
import bean.BiddingBean;
import bean.GoodNoteBean;
import bean.GoodOrderID;
import bean.MessageBean;
import bean.OrderItemBean;
import bean.StatementBillsBean;

/**
 * Created by xulei on 2017/12/4.
 */

public class JsonUtils {
    public static List<OrderItemBean.Order> GetOrderListOnState(BaseBean baseBean){
        List<OrderItemBean.Order> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.result);
            JSONObject object = new JSONObject(str);
            String strarry = object.getString("data");
            JSONArray array = new JSONArray(strarry);
            for(int i=0;i<array.length();i++){
                OrderItemBean.Order noteIDList = new OrderItemBean.Order();
                JSONObject mobject = (JSONObject) array.get(i);

                noteIDList.setOrderID(mobject.getInt("OrderID"));
                noteIDList.setAutographImg(StringUtils.isNull(mobject.getString("AutographImg"))?"":mobject.getString("AutographImg"));
                noteIDList.setOrderNumber(StringUtils.isNull(mobject.getString("OrderNumber"))?"":mobject.getString("OrderNumber"));
                noteIDList.setOrderNumCode(mobject.getInt("OrderNumCode"));
                noteIDList.setDateString(StringUtils.isNull(mobject.getString("DateString"))?"":mobject.getString("DateString"));
                noteIDList.setCreateDate(StringUtils.isNull(mobject.getString("CreateDate"))?"":mobject.getString("CreateDate"));
                try{
                    String DisCompanyName = mobject.getString("DistributionName");
                    noteIDList.setDisCompanyName(StringUtils.isNull(DisCompanyName)?"":DisCompanyName);
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setDisCompanyName("");
                }
                noteIDList.setCityName(StringUtils.isNull(mobject.getString("CityName"))?"":mobject.getString("CityName"));
                noteIDList.setAreaName(StringUtils.isNull(mobject.getString("AreaName"))?"":mobject.getString("AreaName"));
                noteIDList.setMoney(StringUtils.isNull(mobject.getString("Money"))?"":mobject.getString("Money"));
                noteIDList.setContactsrName(StringUtils.isNull(mobject.getString("ContactsrName"))?"":mobject.getString("ContactsrName"));
                noteIDList.setTelePhone(StringUtils.isNull(mobject.getString("TelePhone"))?"":mobject.getString("TelePhone"));
                noteIDList.setDcAddress(StringUtils.isNull(mobject.getString("DcAddress"))?"":mobject.getString("DcAddress"));
                noteIDList.setDistributionID(mobject.getInt("DistributionID"));
                noteIDList.setState(mobject.getInt("State"));
                noteIDList.setIsScore(mobject.getInt("isScore")+"");
                //noteIDList.setTotalAmount(StringUtils.isNull(mobject.getString("TotalAmount"))?"":mobject.getString("TotalAmount"));
                mlist.add(noteIDList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mlist;
    }
    public static List<GoodNoteBean.mNoteIDList> GetGoodsNoteHistoryList(BaseBean baseBean){
        List<GoodNoteBean.mNoteIDList> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                GoodNoteBean.mNoteIDList noteIDList = new GoodNoteBean.mNoteIDList();
                JSONObject mobject = (JSONObject) array.get(i);
                try {
                    noteIDList.setGoodsID(mobject.getInt("GoodsID"));
                }catch (Exception e){
                    noteIDList.setGoodsID(000000);
                }

                noteIDList.setGoodsImg(StringUtils.isNull(mobject.getString("GoodsImg"))?"":mobject.getString("GoodsImg"));
                //noteIDList.setLikeName(StringUtils.isNull(mobject.getString("LikeName"))?"":mobject.getString("LikeName"));
                try{
                    noteIDList.setCreateDate(StringUtils.isNull(mobject.getString("CreateDate"))?"":mobject.getString("CreateDate"));
                }catch (Exception e){
                    noteIDList.setCreateDate("");
                }

                //noteIDList.setAreaID(mobject.getInt("AreaID"));
                try{
                    String Count = mobject.getString("Count");
                    noteIDList.setCount(StringUtils.isNull(Count)?"":Count);
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setCount("");
                }
                noteIDList.setGoodsName(StringUtils.isNull(mobject.getString("GoodsName"))?"":mobject.getString("GoodsName"));
                try{
                    noteIDList.setGoodsNum(StringUtils.isNull(mobject.getString("Count"))?"":mobject.getString("Count"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setGoodsNum("");
                }
                noteIDList.setGoodsUnit(StringUtils.isNull(mobject.getString("Unit"))?"":mobject.getString("Unit"));
                try{
                    noteIDList.setMoney(StringUtils.isNull(mobject.getString("Money"))?"":mobject.getString("Money"));//酒店标价
                }catch (Exception e){
                    noteIDList.setMoney("0");//酒店标价
                }
                noteIDList.setPrice(StringUtils.isNull(mobject.getString("Price"))?"":mobject.getString("Price"));//报价
                noteIDList.setDateString(StringUtils.isNull(mobject.getString("DateString"))?"":mobject.getString("DateString"));
                try{
                    noteIDList.setState(StringUtils.isNull(mobject.getString("State"))?"":mobject.getString("State"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setState("");
                }

                // noteIDList.setSettlementPrice(StringUtils.isNull(mobject.getString("SettlementPrice"))?"":mobject.getString("SettlementPrice"));
                //noteIDList.setNoteIDList(StringUtils.isNull(mobject.getString("NoteIDList"))?"":mobject.getString("NoteIDList"));
                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }
    public static List<GoodNoteBean.mNoteIDList> GetGoodsNoteHistoryPriceList(BaseBean baseBean){
        List<GoodNoteBean.mNoteIDList> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                GoodNoteBean.mNoteIDList noteIDList = new GoodNoteBean.mNoteIDList();
                JSONObject mobject = (JSONObject) array.get(i);
                try {
                    noteIDList.setGoodsID(mobject.getInt("GoodsID"));
                }catch (Exception e){
                    noteIDList.setGoodsID(000000);
                }

                noteIDList.setGoodsImg(StringUtils.isNull(mobject.getString("GoodsImg"))?"":mobject.getString("GoodsImg"));
                //noteIDList.setLikeName(StringUtils.isNull(mobject.getString("LikeName"))?"":mobject.getString("LikeName"));
                try{
                    noteIDList.setCreateDate(StringUtils.isNull(mobject.getString("CreateDate"))?"":mobject.getString("CreateDate"));
                }catch (Exception e){
                    noteIDList.setCreateDate("");
                }

                //noteIDList.setAreaID(mobject.getInt("AreaID"));
//                try{
//                    String Count = mobject.getString("Count");
//                    noteIDList.setGoodsNum(StringUtils.isNull(Count)?"":Count);
//                }catch (Exception e){
//                    e.printStackTrace();
//                    noteIDList.setGoodsNum("");
//                }
                noteIDList.setGoodsName(StringUtils.isNull(mobject.getString("GoodsName"))?"":mobject.getString("GoodsName"));
                try{
                    noteIDList.setGoodsNum(StringUtils.isNull(mobject.getString("GoodsNum"))?"":mobject.getString("GoodsNum"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setGoodsNum("");
                }
                noteIDList.setGoodsUnit(StringUtils.isNull(mobject.getString("Unit"))?"":mobject.getString("Unit"));
                try{
                    noteIDList.setState(StringUtils.isNull(mobject.getString("State"))?"":mobject.getString("State"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setState("");
                }
                noteIDList.setPrice(StringUtils.isNull(mobject.getString("Price"))?"":mobject.getString("Price"));//报价
                noteIDList.setTrimPrice(StringUtils.isNull(mobject.getString("TrimPrice"))?"":mobject.getString("TrimPrice"));//报价
                // noteIDList.setSettlementPrice(StringUtils.isNull(mobject.getString("SettlementPrice"))?"":mobject.getString("SettlementPrice"));
                //noteIDList.setNoteIDList(StringUtils.isNull(mobject.getString("NoteIDList"))?"":mobject.getString("NoteIDList"));
                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }
    public static List<GoodNoteBean.mNoteIDList> GetGoodsNoteListByPage(BaseBean baseBean){
        List<GoodNoteBean.mNoteIDList> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                GoodNoteBean.mNoteIDList noteIDList = new GoodNoteBean.mNoteIDList();
                JSONObject mobject = (JSONObject) array.get(i);
                try {
                    noteIDList.setGoodsID(mobject.getInt("GoodsID"));
                }catch (Exception e){
                    noteIDList.setGoodsID(000000);
                }

                noteIDList.setGoodsImg(StringUtils.isNull(mobject.getString("GoodsImg"))?"":mobject.getString("GoodsImg"));
                //noteIDList.setLikeName(StringUtils.isNull(mobject.getString("LikeName"))?"":mobject.getString("LikeName"));
                try{
                    noteIDList.setCreateDate(StringUtils.isNull(mobject.getString("CreateDate"))?"":mobject.getString("CreateDate"));
                }catch (Exception e){
                    noteIDList.setCreateDate("");
                }

                //noteIDList.setAreaID(mobject.getInt("AreaID"));
//                try{
//                    String Count = mobject.getString("Count");
//                    noteIDList.setGoodsNum(StringUtils.isNull(Count)?"":Count);
//                }catch (Exception e){
//                    e.printStackTrace();
//                    noteIDList.setGoodsNum("");
//                }

                noteIDList.setGoodsName(StringUtils.isNull(mobject.getString("GoodsName"))?"":mobject.getString("GoodsName"));
                try{
                    noteIDList.setGoodsNum(StringUtils.isNull(mobject.getString("GoodsNum"))?"":mobject.getString("GoodsNum"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setGoodsNum("");
                }
                noteIDList.setGoodsUnit(StringUtils.isNull(mobject.getString("Unit"))?"":mobject.getString("Unit"));
                try{
                    noteIDList.setState(StringUtils.isNull(mobject.getString("State"))?"":mobject.getString("State"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setState("");
                }
                noteIDList.setPrice(StringUtils.isNull(mobject.getString("Price"))?"":mobject.getString("Price"));
                noteIDList.setTrimPrice(StringUtils.isNull(mobject.getString("TrimPrice"))?"":mobject.getString("TrimPrice"));
               // noteIDList.setSettlementPrice(StringUtils.isNull(mobject.getString("SettlementPrice"))?"":mobject.getString("SettlementPrice"));
                //noteIDList.setNoteIDList(StringUtils.isNull(mobject.getString("NoteIDList"))?"":mobject.getString("NoteIDList"));
                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }


    public static List<GoodNoteBean.mNoteIDList> GetGoodsNotePriceList(BaseBean baseBean){
        List<GoodNoteBean.mNoteIDList> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                GoodNoteBean.mNoteIDList noteIDList = new GoodNoteBean.mNoteIDList();
                JSONObject mobject = (JSONObject) array.get(i);
                try {
                    noteIDList.setGoodsID(mobject.getInt("GoodsID"));
                }catch (Exception e){
                    noteIDList.setGoodsID(000000);
                }

                noteIDList.setGoodsImg(StringUtils.isNull(mobject.getString("GoodsImg"))?"":mobject.getString("GoodsImg"));

                noteIDList.setGoodsName(StringUtils.isNull(mobject.getString("GoodsName"))?"":mobject.getString("GoodsName"));
                try{
                    noteIDList.setGoodsNum(StringUtils.isNull(mobject.getString("Price"))?"":mobject.getString("Price"));
                }catch (Exception e){
                    e.printStackTrace();
                    noteIDList.setGoodsNum("");
                }
                noteIDList.setGoodsUnit(StringUtils.isNull(mobject.getString("Unit"))?"":mobject.getString("Unit"));

                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }
//    public static List<GoodNoteBean.mNoteIDList> GetGoodsNoteHistoryListByPage(BaseBean baseBean){
//        List<GoodNoteBean.mNoteIDList> mlist = new ArrayList<>();
//        try {
//            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
//            JSONArray array = new JSONArray(str);
//            for(int i=0;i<array.length();i++){
//                GoodNoteBean.mNoteIDList noteIDList = new GoodNoteBean.mNoteIDList();
//                JSONObject mobject = (JSONObject) array.get(i);
//
//                noteIDList.setGoodsID(mobject.getInt("GoodsID"));
//                noteIDList.setGoodsImg(StringUtils.isNull(mobject.getString("GoodsImg"))?"":mobject.getString("GoodsImg"));
//                //noteIDList.setLikeName(StringUtils.isNull(mobject.getString("LikeName"))?"":mobject.getString("LikeName"));
//                noteIDList.setCreateDate(StringUtils.isNull(mobject.getString("CreateDate"))?"":mobject.getString("CreateDate"));
//                //noteIDList.setAreaID(mobject.getInt("AreaID"));
//                try{
//                    String Count = mobject.getString("Count");
//                    noteIDList.setGoodsNum(StringUtils.isNull(Count)?"":Count);
//                }catch (Exception e){
//                    e.printStackTrace();
//                    noteIDList.setGoodsNum("");
//                }
//                noteIDList.setGoodsName(StringUtils.isNull(mobject.getString("GoodsName"))?"":mobject.getString("GoodsName"));
//                //noteIDList.setGoodsNum(StringUtils.isNull(mobject.getString("GoodsNum"))?"":mobject.getString("GoodsNum"));
//                noteIDList.setGoodsUnit(StringUtils.isNull(mobject.getString("Unit"))?"":mobject.getString("Unit"));
//                noteIDList.setState(StringUtils.isNull(mobject.getString("State"))?"":mobject.getString("State"));
//                // noteIDList.setSettlementPrice(StringUtils.isNull(mobject.getString("SettlementPrice"))?"":mobject.getString("SettlementPrice"));
//                //noteIDList.setNoteIDList(StringUtils.isNull(mobject.getString("NoteIDList"))?"":mobject.getString("NoteIDList"));
//                mlist.add(noteIDList);
//            }
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        return mlist;
//    }
    public static List<StatementBillsBean> GetBills(BaseBean baseBean){
        List<StatementBillsBean> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.result) ;
            JSONObject object = new JSONObject(str);
            JSONArray array = new JSONArray(object.getString("data"));
            for(int i=0;i<array.length();i++){
                StatementBillsBean noteIDList = new StatementBillsBean();
                JSONObject mobject = (JSONObject) array.get(i);
                noteIDList.setOrderID(StringUtils.isNull(mobject.getString("OrderID"))? "":mobject.getString("OrderID"));
                try{
                    noteIDList.setOrderNumber(StringUtils.isNull(mobject.getString("OrderNumber"))? "":mobject.getString("OrderNumber"));
                }catch (Exception e){
                    noteIDList.setOrderNumber("");
                }
                try{
                    noteIDList.setMoney(mobject.getString("Money"));
                }catch (Exception e){
                    noteIDList.setMoney("");
                }
                try{
                    noteIDList.setDateString(StringUtils.isNull(mobject.getString("DateString"))? "":mobject.getString("DateString"));
                }catch (Exception e){
                    noteIDList.setDateString("");
                }
//                try{
//                    noteIDList.setDiscompanyName(StringUtils.isNull(mobject.getString("DiscompanyName"))? "":mobject.getString("DiscompanyName"));
//                }catch (Exception e){
//                    noteIDList.setDiscompanyName("");
//                }


                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }
    public static List<GoodOrderID> GetOrderByID(BaseBean baseBean){
        List<GoodOrderID> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            //JSONObject object = new JSONObject(str);
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                GoodOrderID noteIDList = new GoodOrderID();
                JSONObject mobject = (JSONObject) array.get(i);
                noteIDList.setGoodOrderID(mobject.getInt("GoodOrderID"));
                noteIDList.setGoodsName(mobject.getString("GoodsName"));
                noteIDList.setUnit(mobject.getString("Unit"));
                noteIDList.setGoodID(mobject.getInt("GoodID"));
                noteIDList.setCount(mobject.getString("Count"));
                noteIDList.setPrice(mobject.getString("Price"));
                noteIDList.setTrimPrice(mobject.getString("TrimPrice"));
                noteIDList.setActualCount(mobject.getString("RealCount"));
               // noteIDList.setTotalCount(mobject.getString("TotalCount"));
               // noteIDList.setState(mobject.getInt("State"));

                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return mlist;
    }
    public static List<MessageBean> GetReadMessage(BaseBean baseBean){
        List<MessageBean> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            //JSONObject object = new JSONObject(str);
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                MessageBean noteIDList = new MessageBean();
                JSONObject mobject = (JSONObject) array.get(i);
                noteIDList.setMessageID(mobject.getInt("MessageID"));
                noteIDList.setIsRead(mobject.getInt("IsRead"));
                noteIDList.setBusinessID(mobject.getInt("BusinessID"));
                noteIDList.setContent(mobject.getString("Content"));
                noteIDList.setCreateDate(mobject.getString("CreateDate"));
                noteIDList.setBusinessType(mobject.getInt("BusinessType"));
                noteIDList.setContent(mobject.getString("Content"));
                noteIDList.setDateString(mobject.getString("DateString"));
                //noteIDList.setMessageType(mobject.getInt("MessageType"));
                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return mlist;
    }

    public static List<BiddingBean> GetBiddingBean(BaseBean baseBean) {
        List<BiddingBean> mlist = new ArrayList<>();
        try {
            String str =  GsonUtils.beanToJSONString(baseBean.data) ;
            //JSONObject object = new JSONObject(str);
            JSONArray array = new JSONArray(str);
            for(int i=0;i<array.length();i++){
                BiddingBean noteIDList = new BiddingBean();
                JSONObject mobject = (JSONObject) array.get(i);
                noteIDList.setGoodOrderID(mobject.getInt("GoodOrderID"));
                noteIDList.setOrderID(mobject.getInt("OrderID"));
                noteIDList.setGoodID(mobject.getInt("GoodID"));
                noteIDList.setGoodsName(mobject.getString("GoodsName"));
                noteIDList.setGoodsImg(mobject.getString("GoodsImg"));
                //noteIDList.setGoodsLikeName(mobject.getString("GoodsLikeName"));
                noteIDList.setUnit(mobject.getString("Unit"));
               // noteIDList.setMoney(mobject.getString("Money"));
                noteIDList.setPrice(mobject.getString("Price"));
                noteIDList.setTrimPrice(mobject.getString("TrimPrice"));
                noteIDList.setCount(mobject.getString("Count"));
                noteIDList.setRealCount(mobject.getString("RealCount"));
                mlist.add(noteIDList);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mlist;
    }
}
